import { system as http } from '@zh/common-utils/http'
export { http }

/**
 * 初始化树
 * @param {Object} params
 */
export function page (params) {
  return http.post('system/SysUnitinfo/unitTableTree', params)
}

/**
 * 初始化树-懒加载
 * @param {*} id   机构ID
 * @returns
 */
export function getUnitTreeNodesByParentId (parentId) {
  return http.post('system/SysUnitinfo/unitTableTreeLazy', parentId)
  // return http.post('system/SysUnitinfo/unitTableTreeLazy', [{ id: parentId }])
}

/**
 * 机构下拉树（全量加载）
 * @param {*}
 * @returns
 */
export function getAllUnit (param) {
  return http.post('/system/SysUnitinfo/getAllUnit', param)
}

/**
 * 人员下拉树（全量加载）
 * @param {*}
 * @returns
 */
export function getAllUser (param) {
  return http.post('/system/SysUnituser/getAllUser', param)
}

/**
 * 查询列表
 * @param {Object} params
 */
export function queryPageTable (params) {
  return http.post('system/SysUnitinfo/queryPageTable', params)
}
/**
 * 初始化上级机构名称
 * @param {Object} params
 */
export function initBelongs (params) {
  return http.post('system/SysUnitinfo/initBelongs', params)
}
/**
 * 启用停用
 * @param checked true：启用 false：停用
 * @param {Long} id 机构id
 */
export function startAndStopState (checked, id) {
  return http.get('system/SysUnitinfo' + (checked ? '/start/' : '/stop/') + id)
}

/**
 * 初始化 修改
 * @param {Long} id 机构id
 */
export function getById (id) {
  return http.get('system/SysUnitinfo/getById/' + id)
}

/**
 * 初始化 新增
 * @param {Long} topId 机构id
 */
export function init (topId) {
  return http.get('system/SysUnitinfo/init/' + topId)
}

/**
 * 删除
 * @param {Long} id 机构id
 */
export function del (id) {
  return http.get('system/SysUnitinfo/delete/' + id)
}

/**
 * 修改或保存
 * @param {Object} form 表单
 */
export function saveOrUpdate (form) {
  const url = form.id ? 'system/SysUnitinfo/update' : 'system/SysUnitinfo/save'
  return http.post(url, form)
}

export function unitTree (topId) {
  return http.post('system/SysUnitinfo/unitTree?topId=' + topId)
}
export function unitTreeV2 (topId) {
  return http.post('system/SysUnitinfo/unitTreeV2')
}
export function getAuthUnitTree (appId) {
  return http.get('app/sysApplicationUnit/getAuthUnitTree/' + appId)
}
/**
 * @param {Long} ids 机构ids
 */
export function getUnitIds (ids) {
  return http.post('system/SysUnitinfo/getUnitIds', ids)
}

export function unitMoveTree (params) {
  return http.post('system/SysUnitinfo/unitMoveTree', params)
}

export function unitMove (params) {
  return http.post('system/SysUnitinfo/unitMove', params)
}

export function unitOrderTree (params) {
  return http.post('system/SysUnitinfo/unitOrderTree', params)
}

export function unitOrder (params) {
  return http.post('system/SysUnitinfo/unitOrder', params)
}
/**
 *  获取测试机构树
 * @param {*} params
 * @returns
 */
export function unitTreeByIsTest (params) {
  return http.get('/system/SysUnitinfo/unitTreeByIsTest/' + params)
}

/**
 * 根据角色获取机构树
 * @param {*} topId 上级机构ID
 * @param {*} isTest 是否测试机构 0-否、1-是
 * @returns
 */
export function unitTreeLazyByRole (topId, isTest) {
  return http.get('/system/SysUnitinfo/unitTreeLazyByRole/' + topId + '/' + isTest)
}